import pymysql


class SqlConnector:
    def __init__(self):
        if not hasattr(self, 'db'):
            self.db = pymysql.connect(host='127.0.0.1', user='root', password='root', port=3306, db='pydb')

    def __new__(cls, *args, **kwargs):
        if not hasattr(cls, 'instance'):
            cls.instance = super().__new__(cls, *args, **kwargs)
        return cls.instance


def connectSql():
    db = pymysql.connect(host='127.0.0.1', user='root', password='root', port=3306, db='pydb')
    cursor = db.cursor()
    sql = 'select * from info'
    cursor.execute(sql)
    res = cursor.fetchall()
    print(res)


if __name__ == '__main__':
    s = SqlConnector()
    s2 = SqlConnector()
    print(id(s.db))
    print(id(s2.db))
